import { reactive } from "vue";
import { DataModel, Operation } from "@/types/global";

export default function useDataModel() {
  const dataModel = reactive<DataModel>({
    visible: false,
    title: '标题',
    disabled: false,
    submit: false,
    type: Operation.PREVIEW
  })

  const openModel = (title: string, disabled: boolean, submit: boolean, type: Operation) => {
    dataModel.title = title
    dataModel.disabled = disabled
    dataModel.submit = submit
    dataModel.type = type
    dataModel.visible = true
  }

  const closeModel = () => {
    dataModel.visible = false
    dataModel.title = ''
    dataModel.disabled = false
    dataModel.submit = false
    dataModel.type = Operation.PREVIEW
  }

  return {
    dataModel,
    openModel,
    closeModel
  }
}
